#ifndef CQTUART_H
#define CQTUART_H

#include <QObject>
#include <QQueue>

#ifdef __linux__   /* Linux */

#include <termios.h>
#include <fcntl.h>

#else

#include <windows.h>

#endif

#include "cprotocole.h"

//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
class MyThread;
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------


class CQtUart : public QObject
{
    Q_OBJECT
public:
    explicit CQtUart(QObject *parent = 0);
    ~CQtUart(void);
    bool Open( char *ComPort, unsigned long BaudRate, unsigned char DataSize,
               unsigned char Parity, unsigned char NbStopBit, EProtocol i_protocole );
    bool Close( void );
    // le buffer est deja alloue
    bool Read( unsigned char *o_pBuffer, unsigned char *o_size);
    QList<unsigned char> GetMsg( void );

    bool Write( unsigned char *i_pBuffer, unsigned char i_size);

    // utiliser par le thread
    void AddMsg( unsigned char *i_buffer, unsigned char i_size );
    //envoi de données
    int PollLinuxComport(unsigned char *buf, int size);

signals:
    void SignalAddMsg();

public slots:

public:
#ifdef __linux__   /* Linux */

    struct termios new_port_settings,
           old_port_settings;
    int Cport,
        error;

#else

    HANDLE	hComm;
    DCB     m_dcb;
    OVERLAPPED oRead;
    OVERLAPPED oWrite;


#endif

    void (*rx_callback_fctn)( unsigned char data);
    CProtocole *p_protocole;

private:
    MyThread *rx_thread;
    // assume que le premier octet est la taille
    QQueue<QList<unsigned char> > rx_msg;
    unsigned char out_rx_msg[RX_BUFFER_SIZE];
};

#endif // CQTUART_H
